package com.testing.classloader;


import java.util.Random;

/**
 * @author Administrator
 */
public class TestOOM {

    public static void main(String[] args) {
        // -Xms8m -Xmx8m -XX:+PrintGCDetails
        Long maxMemory = Runtime.getRuntime().maxMemory();
        Long totalMemory = Runtime.getRuntime().totalMemory();
        // 最大可占用电脑的内存大概为电脑内存的1/4
        System.out.println(maxMemory/(double)1024/1024 + "MB");
        // 运行时占用的内存,大概占可用最大的1/64
        System.out.println(totalMemory/(double)1024/1024 + "MB");

        String name = "11111";
        while (true){
            name += name + new Random(99999999) + new Random(9999999);
        }
    }
}
